//
//  WQMyUserInfoCell.m
//  WisdomQuestor
//
//  Created by 纪景城 on 2024/12/19.
//

#import "WQMyUserInfoCell.h"

@interface WQMyUserInfoCell () <UICollectionViewDataSource, UICollectionViewDelegate>

@end

@implementation WQMyUserInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.clipsToBounds = YES;
        self.backgroundColor = UIColor.clearColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubviews:[NSArray arrayWithObjects:self.backImageView, nil]];
        [self.backImageView addSubviews:[NSArray arrayWithObjects:self.avatarImageView, self.userNameLabel, self.nextImageView, self.jk_collectionView, self.threeLabel, nil]];
        [self fragmentUI_ViewSet];
    }
    return self;
}

#pragma mark ------- UICollectionViewDelegate -------

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 3;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    LabelImageCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[LabelImageCollectionCell kj_runtimeClassName] forIndexPath:indexPath];
    
    [cell myThreeMasLayout];
    
    switch (indexPath.row) {
        case 0:
            cell.imageView.image = kImageName(@"me_xiaodu_ico");
            cell.titleLabel.text = @"小度";
            break;
            
        case 1:
            cell.imageView.image = kImageName(@"me_tx_ico");
            cell.titleLabel.text = @"腾讯小微";
            break;
            
        case 2:
            cell.imageView.image = kImageName(@"me_dingdong_ico");
            cell.titleLabel.text = @"叮咚";
            break;
            
        default:
            break;
    }
    
    
    return cell;
}

#pragma mark ------- Lazy Methods -------

- (void)fragmentUI_ViewSet {
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(kFragmemtFloat(12));
        make.right.equalTo(self.contentView.mas_right).offset(-kFragmemtFloat(12));
        make.top.bottom.equalTo(self.contentView);
    }];
    [self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.backImageView.mas_left).offset(kFragmemtFloat(12));
        make.top.equalTo(self.backImageView.mas_top).offset(kFragmemtFloat(12));
        make.size.mas_equalTo(kSizzleKapadate(57, 57));
    }];
    [self.userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.avatarImageView);
        make.left.equalTo(self.avatarImageView.mas_right).offset(kFragmemtFloat(18));
        make.right.equalTo(self.backImageView.mas_right).offset(-kFragmemtFloat(50));
    }];
    [self.nextImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.avatarImageView);
        make.right.equalTo(self.backImageView.mas_right).offset(-kFragmemtFloat(24));
        make.size.mas_equalTo(kSizzleKapadate(7, 12));
    }];
    [self.jk_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.backImageView);
        make.height.mas_equalTo(kFragmemtFloat(100));
    }];
    [self.threeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.backImageView.mas_left).offset(kFragmemtFloat(16));
        make.bottom.equalTo(self.jk_collectionView.mas_top).offset(-kFragmemtFloat(10));
    }];
}

- (UIImageView *)backImageView {
    if (!_backImageView) {
        _backImageView = [[UIImageView alloc] initWithImage:kImageName(@"me_user_bg")];
        _backImageView.userInteractionEnabled = YES;
    }
    return _backImageView;
}

- (UIImageView *)avatarImageView {
    if (!_avatarImageView) {
        _avatarImageView = [[UIImageView alloc] initWithImage:kImageName(@"base_ profile_picture")];
    }
    return _avatarImageView;
}

- (UILabel *)userNameLabel {
    if (!_userNameLabel) {
        _userNameLabel = [UILabel initWithTextColor:k_Color_222222 weight:UIFontWeightMedium size:15];
        _userNameLabel.text = @"请点击登陆";
    }
    return _userNameLabel;
}

- (UIImageView *)nextImageView {
    if (!_nextImageView) {
        _nextImageView = [[UIImageView alloc] initWithImage:kImageName(@"base_jiantousmall_huise")];
    }
    return _nextImageView;
}

- (UILabel *)threeLabel {
    if (!_threeLabel) {
        _threeLabel = [UILabel initWithTextColor:k_Color_222222 weight:UIFontWeightMedium size:14];
        _threeLabel.text = @"语音等第三方服务";
    }
    return _threeLabel;
}

- (UICollectionView *)jk_collectionView {
    if (!_jk_collectionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake((kScreen_Width - kFragmemtFloat(25)) / 3, kFragmemtFloat(100));
        layout.minimumLineSpacing = 0;
        layout.minimumInteritemSpacing = 0;
//        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        _jk_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:layout];
        _jk_collectionView.backgroundColor = [UIColor clearColor];
        _jk_collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
        _jk_collectionView.showsHorizontalScrollIndicator = NO;
        _jk_collectionView.showsVerticalScrollIndicator = NO;
        _jk_collectionView.scrollEnabled = NO;
        _jk_collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        _jk_collectionView.dataSource = self;
        _jk_collectionView.delegate = self;
        [_jk_collectionView registerClass:[LabelImageCollectionCell class] forCellWithReuseIdentifier:[LabelImageCollectionCell kj_runtimeClassName]];
    }
    return _jk_collectionView;
}

@end
